package org.ruanjj.designmodel.enumsingleton;

//懒汉式，按需创建
//进阶版，加锁解决线程安全问题,但是一开始就加锁或导致效率很低
//缺点都避免不了反射和反序列化创建对象，不能保证单例
public class Singleton2 {
    private static Singleton2 instance;

    private Singleton2(){

    }

    public static synchronized Singleton2 getInstance(){
        if(instance != null){
            instance = new Singleton2();
        }

        return instance;
    }
}
